Game messenger
Data can be exchanged with a wireless device in a channel independent from the normal shell. The default use case is the mobile app during games but it can also be used to interact with a computer through the Command Center.
- Any message starting with ‘>’ will be handled by the game messenger.
- It can hold up to 20 messages in a FIFO.
- Messages can be up to 100 bytes long.
- The Alert (Bell, Beep) character ‘\a’ should NOT be used in print or game messenger strings.
Example
Send leds #RRGGBB from the Command Center to change the color of the LEDs, and exit to stop.
import olem
def parse_msg(msg):
argv = msg.split()
argc = len(argv)
if argv[0] == "leds":
if argc < 2:
print("Not enough args for leds command")
return
if argv[1][0] != '#':
print("Command leds expects a hex color (#RRGGBB) as 2nd arg")
return
olem.led_on(olem.LEDALL, argv[1])
else:
print("Unknown command")
print("start gmsg basic testing")
msg = "no msg received"
while "exit" not in msg:
msg = olem.gmsg_wait_for_message()
parse_msg(msg)
print("end gmsg basic testing")
Functions
gmsg_wait_for_message()
Wait for a message from the mobile app or the Command Center. The game can still be stopped during the wait.
Received messages are kept in a queue of up to 20 messages.
Returns: the oldest message received
gmsg_wait_for_message_timeout(timeout)
Wait for a message from the mobile app or the Command Center, for a limited time.
| Parameter | Description |
|---|---|
timeout | maximum time to wait in ms |
Returns: the oldest message received, or an empty string if no message arrived in time
gmsg_send_message(message)
Send a message to the mobile app or the Command Center.
| Parameter | Description |
|---|---|
message | text of up to 100 bytes. Do not use the alert character "\a". |
gmsg_reset_queue()
Delete the received messages that were not read yet.
gmsg_get_message()
Get the oldest received message, without waiting.
Returns: the oldest message received, or an empty string if there is none
gmsg_get_waiting_message_count()
Returns: number of received messages that were not read yet